using System.Collections.Generic;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using IQIGame.Onigao.Framework;
using System;

namespace IQIGame.Onigao.Logic
{
    public static partial class BattleUpdateFactory
    {
        static BattleUpdateFactory()
        {
            _commandTypes = new Dictionary<Type, EBattleUpdateType>();
            _commandTypes[typeof(BattleCommand_StartPart)] = EBattleUpdateType.StartPart;
            _commandTypes[typeof(BattleCommand_SkillEffective)] = EBattleUpdateType.SkillEffective;
            _commandTypes[typeof(BattleCommand_BuffChange)] = EBattleUpdateType.BuffChange;
            _commandTypes[typeof(BattleCommand_AttrChange)] = EBattleUpdateType.AttrChange;
            _commandTypes[typeof(BattleCommand_PosChange)] = EBattleUpdateType.PosChange;
            _commandTypes[typeof(BattleCommand_Dead)] = EBattleUpdateType.Dead;
            _commandTypes[typeof(BattleCommand_BuffDamage)] = EBattleUpdateType.BuffDamage;
            _commandTypes[typeof(BattleCommand_Shield)] = EBattleUpdateType.Shield;
            _commandTypes[typeof(BattleCommand_CustomProperty)] = EBattleUpdateType.CustomProperty;
            _commandTypes[typeof(BattleCommand_BuffCure)] = EBattleUpdateType.BuffCure;
            _commandTypes[typeof(BattleCommand_AddSkill)] = EBattleUpdateType.AddSkill;
            _commandTypes[typeof(BattleCommand_WeaknessPoint)] = EBattleUpdateType.WeaknessPoint;
            _commandTypes[typeof(BattleCommand_SkillEffectiveStart)] = EBattleUpdateType.SkillEffectiveStart;
            _commandTypes[typeof(BattleCommand_SkillEffectiveEnd)] = EBattleUpdateType.SkillEffectiveEnd;
            _commandTypes[typeof(BattleCommand_Charge)] = EBattleUpdateType.Charge;
            _commandTypes[typeof(BattleCommand_ChargeStop)] = EBattleUpdateType.ChargeStop;
            _commandTypes[typeof(BattleCommand_Morph)] = EBattleUpdateType.Morph;
            _commandTypes[typeof(BattleCommand_Round)] = EBattleUpdateType.Round;
            _commandTypes[typeof(BattleCommand_Turn)] = EBattleUpdateType.Turn;
            _commandTypes[typeof(BattleCommand_PermitCast)] = EBattleUpdateType.PermitCast;
            _commandTypes[typeof(BattleCommand_CastSkill)] = EBattleUpdateType.CastSkill;
            _commandTypes[typeof(BattleCommand_CastSkillComplete)] = EBattleUpdateType.CastSkillComplete;
            _commandTypes[typeof(BattleCommand_Substitute)] = EBattleUpdateType.Substitute;
            _commandTypes[typeof(BattleCommand_NextWave)] = EBattleUpdateType.NextWave;
            _commandTypes[typeof(BattleCommand_SkillEffectiveResponse)] = EBattleUpdateType.SkillEffectiveResponse;
            _commandTypes[typeof(BattleCommand_RemoveUnit)] = EBattleUpdateType.RemoveUnit;
            if (_commandTypes.Count != (int)EBattleUpdateType.Max - 1)
            {
                LogicLog.LogError("BattleUpdateFactory commandTypes is not enough");
            }
        }
        public static object TryParseUpdate(SInputStream rInput)
        {
            ISerializeCustomPOD data = null;
            var rCustomType = (EBattleUpdateType)rInput.Read_byte();
            switch (rCustomType)
            {
            case EBattleUpdateType.StartPart:
               data = BaseBattleCommand.Get<BattleCommand_StartPart>();
               break;
            case EBattleUpdateType.SkillEffective:
               data = BaseBattleCommand.Get<BattleCommand_SkillEffective>();
               break;
            case EBattleUpdateType.BuffChange:
               data = BaseBattleCommand.Get<BattleCommand_BuffChange>();
               break;
            case EBattleUpdateType.AttrChange:
               data = BaseBattleCommand.Get<BattleCommand_AttrChange>();
               break;
            case EBattleUpdateType.PosChange:
               data = BaseBattleCommand.Get<BattleCommand_PosChange>();
               break;
            case EBattleUpdateType.Dead:
               data = BaseBattleCommand.Get<BattleCommand_Dead>();
               break;
            case EBattleUpdateType.BuffDamage:
               data = BaseBattleCommand.Get<BattleCommand_BuffDamage>();
               break;
            case EBattleUpdateType.Shield:
               data = BaseBattleCommand.Get<BattleCommand_Shield>();
               break;
            case EBattleUpdateType.CustomProperty:
               data = BaseBattleCommand.Get<BattleCommand_CustomProperty>();
               break;
            case EBattleUpdateType.BuffCure:
               data = BaseBattleCommand.Get<BattleCommand_BuffCure>();
               break;
            case EBattleUpdateType.AddSkill:
               data = BaseBattleCommand.Get<BattleCommand_AddSkill>();
               break;
            case EBattleUpdateType.WeaknessPoint:
               data = BaseBattleCommand.Get<BattleCommand_WeaknessPoint>();
               break;
            case EBattleUpdateType.SkillEffectiveStart:
               data = BaseBattleCommand.Get<BattleCommand_SkillEffectiveStart>();
               break;
            case EBattleUpdateType.SkillEffectiveEnd:
               data = BaseBattleCommand.Get<BattleCommand_SkillEffectiveEnd>();
               break;
            case EBattleUpdateType.Charge:
               data = BaseBattleCommand.Get<BattleCommand_Charge>();
               break;
            case EBattleUpdateType.ChargeStop:
               data = BaseBattleCommand.Get<BattleCommand_ChargeStop>();
               break;
            case EBattleUpdateType.Morph:
               data = BaseBattleCommand.Get<BattleCommand_Morph>();
               break;
            case EBattleUpdateType.Round:
               data = BaseBattleCommand.Get<BattleCommand_Round>();
               break;
            case EBattleUpdateType.Turn:
               data = BaseBattleCommand.Get<BattleCommand_Turn>();
               break;
            case EBattleUpdateType.PermitCast:
               data = BaseBattleCommand.Get<BattleCommand_PermitCast>();
               break;
            case EBattleUpdateType.CastSkill:
               data = BaseBattleCommand.Get<BattleCommand_CastSkill>();
               break;
            case EBattleUpdateType.CastSkillComplete:
               data = BaseBattleCommand.Get<BattleCommand_CastSkillComplete>();
               break;
            case EBattleUpdateType.Substitute:
               data = BaseBattleCommand.Get<BattleCommand_Substitute>();
               break;
            case EBattleUpdateType.NextWave:
               data = BaseBattleCommand.Get<BattleCommand_NextWave>();
               break;
            case EBattleUpdateType.SkillEffectiveResponse:
               data = BaseBattleCommand.Get<BattleCommand_SkillEffectiveResponse>();
               break;
            case EBattleUpdateType.RemoveUnit:
               data = BaseBattleCommand.Get<BattleCommand_RemoveUnit>();
               break;
            default:
               throw new Exception($"在尝试解析未指定的BattleCommand:{rCustomType}");
            }
            data.DeSerialize(rInput);
            return data;
        }
    }
}
